/*
 * @(#)Director.java	1.0 2000/12/19
 *
 * Copyright 2000 Thomas Barnekow. All Rights Reserved.
 *
 * This software is the proprietary information of Thomas Barnekow.
 * Use is subject to license terms.
 */

package tb.provider.jdbc;

import java.util.*;
import tb.provider.*;

/**
 * This class is part of an implementation of the "Builder" design pattern.
 *
 * @author Thomas Barnekow
 * @version 1.0
 */
public class Director {

  private Builder m_builder;

  public Director(Builder builder) {
    m_builder = builder;
  }

  public MetaObject processDatabase(Database database) throws Exception {
    iterateDatabase(database);
    return m_builder.getResult();
  }

  public MetaObject processSchema(Schema schema) throws Exception {
    iterateSchema(schema);
    return m_builder.getResult();
  }

  public MetaObject processTable(Table table) throws Exception {
    iterateTable(table);
    return m_builder.getResult();
  }

  void iterateDatabase(Database database) throws Exception {
    m_builder.takeDatabase(database);
    Iterator iterator = database.iterator();
    while (iterator.hasNext())
      iterateSchema((Schema) iterator.next());
  }

  void iterateSchema(Schema schema) throws Exception {
    m_builder.takeSchema(schema);
    Iterator iterator = schema.iterator();
    while (iterator.hasNext())
      iterateTable((Table) iterator.next());
  }

  void iterateTable(Table table) throws Exception {
    m_builder.takeTable(table);
    Iterator iterator = table.iterator();
    while (iterator.hasNext())
      m_builder.takeColumn((Column) iterator.next());
  }
}